package com.doone.telmarket.infrastructure.dao.impl;

import com.doone.telmarket.domain.ibator.ServiceKeep;
import com.doone.telmarket.domain.ibator.ServiceKeepExample;
import com.doone.telmarket.infrastructure.dao.ServiceKeepDAO;
import com.ibatis.sqlmap.client.SqlMapClient;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Service;
@Service("serviceKeepDAO")
public class ServiceKeepDAOImpl extends SqlMapClientDaoSupport implements ServiceKeepDAO {

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table TB_TELMARK_SERVICEKEEP
     *
     * @ibatorgenerated Thu Oct 22 10:10:06 CST 2009
     */
    public ServiceKeepDAOImpl() {
        super();
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table TB_TELMARK_SERVICEKEEP
     *
     * @ibatorgenerated Thu Oct 22 10:10:06 CST 2009
     */
    public int countByExample(ServiceKeepExample example) {
        Integer count = (Integer)  getSqlMapClientTemplate().queryForObject("TB_TELMARK_SERVICEKEEP.ibatorgenerated_countByExample", example);
        return count;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table TB_TELMARK_SERVICEKEEP
     *
     * @ibatorgenerated Thu Oct 22 10:10:06 CST 2009
     */
    public int deleteByExample(ServiceKeepExample example) {
        int rows = getSqlMapClientTemplate().delete("TB_TELMARK_SERVICEKEEP.ibatorgenerated_deleteByExample", example);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table TB_TELMARK_SERVICEKEEP
     *
     * @ibatorgenerated Thu Oct 22 10:10:06 CST 2009
     */
    public int deleteByPrimaryKey(Long id) {
        ServiceKeep key = new ServiceKeep();
        key.setId(id);
        int rows = getSqlMapClientTemplate().delete("TB_TELMARK_SERVICEKEEP.ibatorgenerated_deleteByPrimaryKey", key);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table TB_TELMARK_SERVICEKEEP
     *
     * @ibatorgenerated Thu Oct 22 10:10:06 CST 2009
     */
    public Long insert(ServiceKeep record) {
    	List<ServiceKeep> li = getSqlMapClientTemplate().queryForList("TB_TELMARK_SERVICEKEEP.selectByServiceKeep2", record);
    	if(li.size()==0){
    		return (Long)getSqlMapClientTemplate().insert("TB_TELMARK_SERVICEKEEP.ibatorgenerated_insert", record);
    	}else{
    		ServiceKeep s = li.get(0);
    		s.setId(li.get(0).getId());
    		getSqlMapClientTemplate().update("TB_TELMARK_SERVICEKEEP.updateByServiceKeep", s);
    		return (Long)s.getId();
    	}
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table TB_TELMARK_SERVICEKEEP
     *
     * @ibatorgenerated Thu Oct 22 10:10:06 CST 2009
     */
    public Long insertSelective(ServiceKeep record) {
        Object newKey = getSqlMapClientTemplate().insert("TB_TELMARK_SERVICEKEEP.ibatorgenerated_insertSelective", record);
        return (Long) newKey;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table TB_TELMARK_SERVICEKEEP
     *
     * @ibatorgenerated Thu Oct 22 10:10:06 CST 2009
     */
    @SuppressWarnings("unchecked")
    public List<ServiceKeep> selectByExample(ServiceKeepExample example) {
        List<ServiceKeep> list = getSqlMapClientTemplate().queryForList("TB_TELMARK_SERVICEKEEP.ibatorgenerated_selectByExample", example);
        return list;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table TB_TELMARK_SERVICEKEEP
     *
     * @ibatorgenerated Thu Oct 22 10:10:06 CST 2009
     */
    public ServiceKeep selectByPrimaryKey(Long id) {
        ServiceKeep key = new ServiceKeep();
        key.setId(id);
        ServiceKeep record = (ServiceKeep) getSqlMapClientTemplate().queryForObject("TB_TELMARK_SERVICEKEEP.ibatorgenerated_selectByPrimaryKey", key);
        return record;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table TB_TELMARK_SERVICEKEEP
     *
     * @ibatorgenerated Thu Oct 22 10:10:06 CST 2009
     */
    public int updateByExampleSelective(ServiceKeep record, ServiceKeepExample example) {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = getSqlMapClientTemplate().update("TB_TELMARK_SERVICEKEEP.ibatorgenerated_updateByExampleSelective", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table TB_TELMARK_SERVICEKEEP
     *
     * @ibatorgenerated Thu Oct 22 10:10:06 CST 2009
     */
    public int updateByExample(ServiceKeep record, ServiceKeepExample example) {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = getSqlMapClientTemplate().update("TB_TELMARK_SERVICEKEEP.ibatorgenerated_updateByExample", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table TB_TELMARK_SERVICEKEEP
     *
     * @ibatorgenerated Thu Oct 22 10:10:06 CST 2009
     */
    public int updateByPrimaryKeySelective(ServiceKeep record) {
        int rows = getSqlMapClientTemplate().update("TB_TELMARK_SERVICEKEEP.ibatorgenerated_updateByPrimaryKeySelective", record);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table TB_TELMARK_SERVICEKEEP
     *
     * @ibatorgenerated Thu Oct 22 10:10:06 CST 2009
     */
    public int updateByPrimaryKey(ServiceKeep record) {
        int rows = getSqlMapClientTemplate().update("TB_TELMARK_SERVICEKEEP.ibatorgenerated_updateByPrimaryKey", record);
        return rows;
    }

    /**
     * This class was generated by Apache iBATIS ibator.
     * This class corresponds to the database table TB_TELMARK_SERVICEKEEP
     *
     * @ibatorgenerated Thu Oct 22 10:10:06 CST 2009
     */
    private static class UpdateByExampleParms extends ServiceKeepExample {
        private Object record;

        public UpdateByExampleParms(Object record, ServiceKeepExample example) {
            super(example);
            this.record = record;
        }

        public Object getRecord() {
            return record;
        }
    }
    
	public List<ServiceKeep> selectByServiceKeep(ServiceKeep sk) {
		return getSqlMapClientTemplate().queryForList("TB_TELMARK_SERVICEKEEP.selectByServiceKeep", sk);
	}
    
    @Autowired
	public void setSqlMapClientBase(SqlMapClient sqlMapClient) {
		super.setSqlMapClient(sqlMapClient);
	}

	public void deleteByServiceCode(int serviceCode) {
		
		getSqlMapClientTemplate().delete("TB_TELMARK_SERVICEKEEP.deleteByServiceCode", serviceCode);
	}

	
}